﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Info_UpdateStudentInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserName"] == null)
        {
            Response.Write("<script>alert('请先登录!');window.location.href='../Login.aspx'</script>");
        }
        else
        {
            if (!IsPostBack)
            {
                int studentID = Convert.ToInt32(Request["studentID"].ToString());
                ArrayList al = new Sqlselete().SelectStu(studentID);
                for (int i = 0; i < al.Count; i++)
                {
                    this.TextBox1.Text = al[0].ToString();
                    this.TextBox2.Text = al[2].ToString();
                    this.TextBox3.Text = al[1].ToString();
                    this.TextBox4.Text = al[3].ToString();
                    this.TextBox5.Text = al[4].ToString();
                    this.TextBox6.Text = al[5].ToString();

                }
                ArrayList al1 = new Sqlselete().SelectClassId();
                for (int j = 0; j < al1.Count; j++)
                {
                    DropDownList1.Items.Add(al1[j].ToString());
                }
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        int studentID = Convert.ToInt32(Request["studentID"].ToString());
        string Name = this.TextBox1.Text.Trim() ;
        string Sex = this.TextBox2.Text.Trim();
        int Age = Convert.ToInt32(this.TextBox3.Text);
        string Address = this.TextBox4.Text.Trim();
        string phone = this.TextBox5.Text.Trim();
        string Classid = this.TextBox6.Text.Trim();
        SqlUpdate su = new SqlUpdate();
        if (su.UpdateStudentInfo(studentID, Name, Age, Sex, Address, phone, Classid) > 0)
        {
            string UserName = Session["UserName"].ToString();
            string Workinfo="修改了"+Name+"同学信息";
            SqlInsert sl = new SqlInsert();
            sl.InsertWorkLog(UserName,Request.UserHostAddress.ToString(),Workinfo);
            Response.Write("<script>alert('修改成功！！');window.close();</script>");
        }
        else
        {
            Response.Write("<script>alert('对不起,不能删除！！')</script>");
        }
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.TextBox6.Text = DropDownList1.SelectedItem.Text;
    }
}
